/*
 * @lc app=leetcode.cn id=155 lang=cpp
 *
 * [155] 最小栈
 */
#include <iostream>
#include <vector>
using namespace std;

// @lc code=start
class MinStack
{
  private:
    vector<int> minstack;
    int stack_min = INT_MAX;

  public:
    MinStack() {}

    void push(int val)
    {
        minstack.push_back(val);
        stack_min = min(stack_min, val);
    }

    void pop()
    {
        minstack.pop_back();
        stack_min = INT_MAX;
        for (auto value : minstack) {
            stack_min = min(stack_min, value);
        }
    }

    int top() { return minstack.back(); }

    int getMin() { return stack_min; }
};

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack* obj = new MinStack();
 * obj->push(val);
 * obj->pop();
 * int param_3 = obj->top();
 * int param_4 = obj->getMin();
 */
// @lc code=end

int main()
{
    MinStack *obj = new MinStack();
    obj->push(-2);
    obj->push(0);
    obj->push(-1);
    cout << "Get min: " << obj->getMin() << endl;
    cout << "Get top: " << obj->top() << endl;
    obj->pop();
    cout << "Get min: " << obj->getMin() << endl;
    return 0;
}
